<template>

  <div id="login-contain">
    <div class="nav-title"></div>
    <div class="nav"></div>
    <div class="reg-box">
      <div id="errMsg1" class="errMsg" v-if="showError">手机号或密码错误!</div>
      <form name="login" id="login" onsubmit="return false" >
        <div class="us-name">
          <input type="text" id="login_userId" maxlength="100" placeholder="用户ID/手机号/邮箱" name="logonId"
          v-model="person.telephone">
          <span></span>
        </div>
        <div class="us-pasd">
          <input id="login_userPassword" type="password" maxlength="100" placeholder="密码" name="passwordId"
          v-model="person.password">
          <span></span>
        </div>
      </form>
    </div>
    <div id="forget-pwd">
      <span class="wj"><a >忘记密码？</a></span>
    </div>
    <button id="login_result" class="btn btn-info" @click="loginClick(person.telephone,person.password)">登录</button>
  </div>

</template>

<script>
import router from "../router";
import {request} from "../network/request";

export default {
  name: "Login",
  methods:{
    loginClick:function (telephone,password){
      // this.$router.push('/home')
      console.log(telephone,password
      )
      request({
        url:'/login',
        params:{
            telephone:telephone,
            password:password
        }
      }).then(result => {

        if (result.data.code == -1){
          this.showError = true;
        }
        if(result.data.code == 200){
          switch (result.data.detail.capacity){
            case '111':
              console.log(result.data.detail)
              this.$router.push({
                path:'/posthome',
                query:{
                  tid:result.data.detail.tid,
                  personName:result.data.detail.personName,
                  capacity:result.data.detail.capacity,
                  telephone:result.data.detail.telephone,
                  unitCompany:result.data.detail.unitCompany,
                }
              })
              break;
          }
        }
      }).catch(error => {
        console.log(error);
      })
    }
  },
  data(){
    return{
        person:{
          telephone:'',
          password:''
        },
      msg:'',
      showError:false
    }
  }
}
</script>

<style scoped>
</style>
